//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CShadingPass10.cpp>
///	@path	~/src/graphics/dx10/
///	@date	2009/01/01
///	@desc	.

#include "config/config.h"

#include "lib/system/thread_debug.h"

#include "graphics/dx10/import_dx10.h"
#include "graphics/dx10/CShadingPass10.h"
#include "graphics/dx10/CRenderer10.h"
#include "graphics/common/CPerspectiveView.h"

namespace xeres {

	IMPL_IOBJECT_CLASS_DYNAMIC( CShadingPass10 );

	// ctor
	CShadingPass10::CShadingPass10( void )
		: m_backgroundColor( 0 )
	{
		m_view = new CPerspectiveView;
	}

	// dtor
	CShadingPass10::~CShadingPass10( void )
	{
	}

	// initialize
	void CShadingPass10::Initialize( RefWeak<IDevice> device )
	{
		TRACK_FUNCTION_SCOPE();
		RUNNING_ON_THREAD( _S("device") );
		// we should make buffer here
	}

	// finalize
	void CShadingPass10::Finalize( void )
	{
		TRACK_FUNCTION_SCOPE();
		RUNNING_ON_THREAD( _S("device") );
	}

	// begin pass
	void CShadingPass10::Begin( RenderContext& rc )
	{
		TRACK_FUNCTION_SCOPE();
		RUNNING_ON_THREAD( _S("render") );

		//rc.GetRenderer10()->RestoreDefaultState();

		rc.ClearColorAndDepth( m_backgroundColor , 1.f );

// 		D3D10_VIEWPORT viewport = { 0 , 0 , rc.ResX<int>() , rc.ResY<int>() , 0 , 1 };
// 		rc.GetDX10()->RSSetViewports( 1 , &viewport );

		if( m_view.IsValid() )
		{
			m_view->Reset( rc );

//			Matrix<float> transform = m_view->GetTransform();
//			Matrix<float> projection = m_view->GetProjection();
			// Setup camera.
// 			rc.GetDX9()->SetTransform( D3DTS_WORLD , (const D3DMATRIX*)&Matrix<float>::_identity() );
// 			rc.GetDX9()->SetTransform( D3DTS_VIEW , (D3DMATRIX*)&transform );
// 			rc.GetDX9()->SetTransform( D3DTS_PROJECTION , (D3DMATRIX*)&projection );
		}
		else
		{
// 			rc.GetDX9()->SetTransform( D3DTS_WORLD , (const D3DMATRIX*)&Matrix<float>::_identity() );
// 			rc.GetDX9()->SetTransform( D3DTS_VIEW , (const D3DMATRIX*)&Matrix<float>::_identity() );
// 			rc.GetDX9()->SetTransform( D3DTS_PROJECTION , (const D3DMATRIX*)&Matrix<float>::_identity() );
		}
	}

	// end pass
	void CShadingPass10::End( RenderContext& rc )
	{
		TRACK_FUNCTION_SCOPE();
		RUNNING_ON_THREAD( _S("render") );
	}

	// SetPassView
	void CShadingPass10::SetPassView( RefWeak<IView> view )
	{
		m_view = view;
	}
	// GetPassView
	RefWeak<IView> CShadingPass10::GetPassView( void )
	{
		return m_view;
	}

} // namespace xeres
